clear
version 8.0
#delimit ;
cd "Z:\interactionmodels\";                       * SET WORKING DIRECTORY;
log using results\magnitudefig_FIG2.log, replace;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      magnitudefig_FIG2.do                            *;
*       Date:           01/09/2007                                      *;
*       Author:         MRG                                             *;
*       Purpose:        Creates figure 2 showing effect of magnitude    *;
*                       on number of parties using MSG data             *;
*       Input File:     STATA_mozaffar.dta, golder1.dta                 *;
*       Output File:    magnitudefig_FIG2.log                           *;
*       Data Output:    none                                            *;
*       Previous file:                                                  *;
*       Machine:                                                        *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;
use getdata\STATA_mozaffar.dta;
set obs 100;


*     ****************************************************************  *;
*     ****************************************************************  *;
*           Effect of Magnitude on Number of Legislative Parties        *;
*               MSG data, FIGURE 2 (left) in paper                      *;
*     ****************************************************************  *;
*     ****************************************************************  *;

regress legparties  fragmentation concentration logmag10 frag_conc logmag10_frag  
logmag10_conc logmag10_frag_conc proximity prescandidate prox_prescandidate, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (FRAGMENTATION) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    
replace JH=. if _n>100;

generate str1 txt="*";


*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];
scalar b8=b[1,8];
scalar b9=b[1,9];
scalar b10=b[1,10];




scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar varb8=V[8,8];
scalar varb9=V[9,9];
scalar varb10=V[10,10];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7];
scalar covb3b5=V[3,5];
scalar covb3b6=V[3,6];
scalar covb3b7=V[3,7];
scalar covb5b6=V[5,6];
scalar covb6b7=V[6,7];
scalar covb4b5=V[4,5];
scalar covb4b7=V[4,7];
scalar covb5b7=V[5,7];
scalar covb8b10=V[5,7];


set more off;

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for logmag      *;
*     ****************************************************************  *;

gen conb0=b3+b5*JH+b6*0+b7*(0*JH) if _n<100;
gen conb1=b3+b5*JH+b6*1+b7*(1*JH) if _n<100;
gen conb2=b3+b5*JH+b6*2+b7*(2*JH) if _n<100;
gen conb3=b3+b5*JH+b6*3+b7*(3*JH) if _n<100;
gen conb4=b3+b5*JH+b6*4+b7*(4*JH) if _n<100;


set more off;


*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse0=sqrt(varb3
                + varb5*JH^2 + varb6*(0^2) + varb7*(JH^2)*(0^2)
                + 2*JH*covb3b5 + 2*0*covb3b6 + 2*0*JH*covb3b7 + 2*0*JH*covb5b6
                + 2*0*(JH^2)*covb5b7) + 2*(0^2)*JH*covb6b7  if _n<100;
                
gen conse1=sqrt(varb3
                + varb5*JH^2 + varb6*(1^2) + varb7*(JH^2)*(1^2)
                + 2*JH*covb3b5 + 2*1*covb3b6 + 2*1*JH*covb3b7 + 2*1*JH*covb5b6
                + 2*1*(JH^2)*covb5b7) + 2*(1^2)*JH*covb6b7  if _n<100;
                
gen conse2=sqrt(varb3
                + varb5*JH^2 + varb6*(2^2) + varb7*(JH^2)*(2^2)
                + 2*JH*covb3b5 + 2*2*covb3b6 + 2*2*JH*covb3b7 + 2*2*JH*covb5b6
                + 2*2*(JH^2)*covb5b7) + 2*(2^2)*JH*covb6b7  if _n<100;
                
gen conse3=sqrt(varb3
                + varb5*JH^2 + varb6*(3^2) + varb7*(JH^2)*(3^2)
                + 2*JH*covb3b5 + 2*3*covb3b6 + 2*3*JH*covb3b7 + 2*3*JH*covb5b6
                + 2*3*(JH^2)*covb5b7) + 2*(3^2)*JH*covb6b7  if _n<100;
                
gen conse4=sqrt(varb3
                + varb5*JH^2 + varb6*(4^2) + varb7*(JH^2)*(4^2)
                + 2*JH*covb3b5 + 2*4*covb3b6 + 2*4*JH*covb3b7 + 2*4*JH*covb5b6
                + 2*4*(JH^2)*covb5b7) + 2*(4^2)*JH*covb6b7  if _n<100;
                
set more off;

*     ****************************************************************  *;
*                           Create t statistics                         *;
*     ****************************************************************  *;

gen t0=conb0/conse0;
gen t1=conb1/conse1;
gen t2=conb2/conse2;
gen t3=conb3/conse3;
gen t4=conb4/conse4;

*     ****************************************************************  *;
*       Generate a variable equal to conditional betas                  *;
*     ****************************************************************  *;

gen consb0=conb0;
gen consb1=conb1;
gen consb2=conb2;
gen consb3=conb3;
gen consb4=conb4;




*     ****************************************************************  *;
*       Replace consb_ = missing if t score not bigger than cutoff      *;
*     ****************************************************************  *;

replace consb0 = . if abs(t0)<2.01;
replace consb1 = . if abs(t1)<2.01;
replace consb2 = . if abs(t2)<2.01;
replace consb3 = . if abs(t3)<2.01;
replace consb4 = . if abs(t4)<2.01;

set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of runoff on enpres conditional on eneg        *;
*     ****************************************************************  *;

graph twoway   line conb0 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb0 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb1 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb1 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb2 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb2 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb3 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb3 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)        
        ||  ,   
            ysize(6)
            xsize(8)
            xlabel(0 1 2 3 4 5 6 7 8 9 10, labsize(2.5)) 
            ylabel(-2 -1 0 1 2 3, labsize(2.5))
            yscale(noline)
            xscale(noline)
            yline(0, lcolor(black)) yline(-4 -3 -2 -1 1 2 3 4 5 6, lcolor(white)) 
            xtitle("")
            ytitle("")
            xsca(titlegap(2))
            ysca(titlegap(4.5))
            text(2.9 2.7 "* indicates significance at the 95% level", justification(left) size(2.5))
            legend(off)
            scheme(s2mono) graphregion(fcolor(white))
            graphregion(margin(r=28));

     
*     ****************************************************************  *;
*                               Save Graph                              *;
*     ****************************************************************  *;

translate @Graph results\FIG2_LEFT_logmag_leg.wmf, replace;

list country year fragmentation concentration if fragmentation<1.7 & concentration>1.01 & concentration<2.99;

list country year fragmentation concentration if fragmentation<3.4 & concentration>2.01;

*     ****************************************************************  *;
*       Overall there are 12 observations for which logmag seems to     *;
*       have a significant negative effect on the number of legislative *;
*       parties.                                                        *;
*     ****************************************************************  *;

drop JH conb0 conb1 conb2 conb3 conb4 consb0 consb1 consb2 consb3 consb4 
conse0 conse1 conse2 conse3 conse4 t0 t1 t2 t3 t4 txt;


*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;



*     ****************************************************************  *;
*     ****************************************************************  *;
*               Magnitude Figure for Legislative Parties                *;
*               Golder data, FIGURE 2 (right) in paper                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

clear;
use getdata\golder1.dta;

*     ****************************************************************  *;
*                   Now do recode of concentration                      *;
*     ****************************************************************  *;
                     
gen conc1 = concentration;
replace conc1 = 3 if (fragmentation==1 & concentration==0);
gen frag_conc = fragmentation*conc1;
gen logmag_conc1_nyu = logmag_nyu*conc1;
gen frag_conc1_logmag_nyu = fragmentation*conc1*logmag_nyu;

list if conc1>3 & conc1!=.;
replace conc1 = 3 if conc1>3 & conc1!=.;

regress legparties_nyu  fragmentation conc1 logmag_nyu 
        frag_conc_nyu logmag_frag_nyu logmag_conc1_nyu 
        frag_conc1_logmag_nyu proximity_nyu prescandidate_nyu 
        prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (FRAGMENTATION) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    
replace JH=. if _n>100;

generate str1 txt="*";


*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];
scalar b8=b[1,8];
scalar b9=b[1,9];
scalar b10=b[1,10];




scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar varb8=V[8,8];
scalar varb9=V[9,9];
scalar varb10=V[10,10];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7];
scalar covb3b5=V[3,5];
scalar covb3b6=V[3,6];
scalar covb3b7=V[3,7];
scalar covb5b6=V[5,6];
scalar covb6b7=V[6,7];
scalar covb4b5=V[4,5];
scalar covb4b7=V[4,7];
scalar covb5b7=V[5,7];
scalar covb8b10=V[5,7];


set more off;

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for logmag      *;
*     ****************************************************************  *;

gen conb0=b3+b5*JH+b6*0+b7*(0*JH) if _n<100;
gen conb1=b3+b5*JH+b6*1+b7*(1*JH) if _n<100;
gen conb2=b3+b5*JH+b6*2+b7*(2*JH) if _n<100;
gen conb3=b3+b5*JH+b6*3+b7*(3*JH) if _n<100;
gen conb4=b3+b5*JH+b6*4+b7*(4*JH) if _n<100;


set more off;


*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse0=sqrt(varb3
                + varb5*JH^2 + varb6*(0^2) + varb7*(JH^2)*(0^2)
                + 2*JH*covb3b5 + 2*0*covb3b6 + 2*0*JH*covb3b7 + 2*0*JH*covb5b6
                + 2*0*(JH^2)*covb5b7) + 2*(0^2)*JH*covb6b7  if _n<100;
                
gen conse1=sqrt(varb3
                + varb5*JH^2 + varb6*(1^2) + varb7*(JH^2)*(1^2)
                + 2*JH*covb3b5 + 2*1*covb3b6 + 2*1*JH*covb3b7 + 2*1*JH*covb5b6
                + 2*1*(JH^2)*covb5b7) + 2*(1^2)*JH*covb6b7  if _n<100;
                
gen conse2=sqrt(varb3
                + varb5*JH^2 + varb6*(2^2) + varb7*(JH^2)*(2^2)
                + 2*JH*covb3b5 + 2*2*covb3b6 + 2*2*JH*covb3b7 + 2*2*JH*covb5b6
                + 2*2*(JH^2)*covb5b7) + 2*(2^2)*JH*covb6b7  if _n<100;
                
gen conse3=sqrt(varb3
                + varb5*JH^2 + varb6*(3^2) + varb7*(JH^2)*(3^2)
                + 2*JH*covb3b5 + 2*3*covb3b6 + 2*3*JH*covb3b7 + 2*3*JH*covb5b6
                + 2*3*(JH^2)*covb5b7) + 2*(3^2)*JH*covb6b7  if _n<100;
                
gen conse4=sqrt(varb3
                + varb5*JH^2 + varb6*(4^2) + varb7*(JH^2)*(4^2)
                + 2*JH*covb3b5 + 2*4*covb3b6 + 2*4*JH*covb3b7 + 2*4*JH*covb5b6
                + 2*4*(JH^2)*covb5b7) + 2*(4^2)*JH*covb6b7  if _n<100;
                
set more off;

*     ****************************************************************  *;
*                           Create t statistics                         *;
*     ****************************************************************  *;

gen t0=conb0/conse0;
gen t1=conb1/conse1;
gen t2=conb2/conse2;
gen t3=conb3/conse3;
gen t4=conb4/conse4;

*     ****************************************************************  *;
*       Generate a variable equal to conditional betas                  *;
*     ****************************************************************  *;

gen consb0=conb0;
gen consb1=conb1;
gen consb2=conb2;
gen consb3=conb3;
gen consb4=conb4;




*     ****************************************************************  *;
*       Replace consb_ = missing if t score not bigger than cutoff      *;
*     ****************************************************************  *;

replace consb0 = . if abs(t0)<2.01;
replace consb1 = . if abs(t1)<2.01;
replace consb2 = . if abs(t2)<2.01;
replace consb3 = . if abs(t3)<2.01;
replace consb4 = . if abs(t4)<2.01;

set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of runoff on enpres conditional on eneg        *;
*     ****************************************************************  *;

graph twoway   line conb0 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb0 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb1 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb1 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb2 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb2 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb3 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb3 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)        
        ||  ,   
            ysize(6)
            xsize(8)
            xlabel(0 1 2 3 4 5 6 7 8 9 10, labsize(2.5)) 
            ylabel(-2 -1 0 1 2 3, labsize(2.5))
            yscale(noline)
            xscale(noline)
            yline(0, lcolor(black)) yline(-4 -3 -2 -1 1 2 3 4 5 6, lcolor(white)) 
            xtitle("")
            ytitle("")
            xsca(titlegap(2))
            ysca(titlegap(4.5))
            text(2.9 2.7 "* indicates significance at the 95% level", justification(left) size(2.5))
            legend(off)
            scheme(s2mono) graphregion(fcolor(white))
            graphregion(margin(r=28));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph results\FIG2_RIGHT_logmag_leg.wmf, replace;

drop JH conb0 conb1 conb2 conb3 conb4 consb0 consb1 consb2 consb3 consb4 
conse0 conse1 conse2 conse3 conse4 t0 t1 t2 t3 t4 txt;

log close;
exit;
